#include "bench.h"
#include "../log/log.h"

void sync_bench_thread_log(size_t thread_count, size_t msg_count, size_t msglen)
{
    static int num = 1;
    std::string logger_name = "sync_bench_logger" + std::to_string(num++);
    printf("************************************************\n");
    printf("同步日志测试: %d threads, %d messages\n", thread_count, msg_count);

    Log::GlobalLoggerBuilder::ptr lbp(new Log::GlobalLoggerBuilder());
    lbp->buildloggerName(logger_name);
    lbp->buildloggerFormater("%m");
    lbp->buildsink<Log::FileSink>("./logfile/sync.log");
    lbp->buildLoggerType(Log::BuildType::LOGGER_SYNC);
    lbp->build();
    Log::bench(logger_name, thread_count, msg_count, msglen);
    printf("************************************************\n");
}

void async_bench_thread_log(size_t thread_count, size_t msg_count, size_t msglen)
{
    static int num = 1;
    std::string logger_name = "async_bench_logger" + std::to_string(num++);
    printf("************************************************\n");
    printf("异步日志测试: %d threads, %d messages\n", thread_count, msg_count);

    Log::GlobalLoggerBuilder::ptr lbp(new Log::GlobalLoggerBuilder());
    lbp->buildloggerName(logger_name);
    lbp->buildloggerFormater("%m");
    lbp->buildAsyncUnSafe();
    lbp->buildsink<Log::FileSink>("./logfile/async.log");
    lbp->buildLoggerType(Log::BuildType::LOGGER_ASYNC);
    lbp->build();
    Log::bench(logger_name, thread_count, msg_count, msglen);
    printf("************************************************\n");
}

int main()
{
    sync_bench_thread_log(1, 1000000, 100);
    sync_bench_thread_log(3, 1000000, 100);

    async_bench_thread_log(1, 1000000, 100);
    async_bench_thread_log(3, 1000000, 100);
    return 0;
}